#include <iostream>
#include <string>
#include <sstream>

bool is_prime(int num) {
    if (num <= 1) {
        return false;
    }
    for (int i = 2; i <= num / 2; i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::string words[] = {"zero", "one", "two", "three", "four",
                            "five", "six", "seven", "eight", "nine"}; 
    std::string input, word1, word2, word3;
    std::getline(std::cin, input);
    std::stringstream ss(input);
    ss >> word1 >> word2 >> word3;
    // Проверка на правильность введенных слов
    bool valid_input = false;
    int number = 0;
    for (int i = 0; i < 10 && !valid_input; i++) {
        for (int j = 0; j < 10 && !valid_input; j++) {
            for (int k = 0; k < 10 && !valid_input; k++) {
                if (word1 == words[i] && word2 == words[j] && word3 == words[k]) {
                    number = i * 100 + j * 10 + k;
                    valid_input = true;
                }
            }
        }
    }
    if (!valid_input || word3.empty()) {
        std::cout << "Wrong input";
        return 0;
    }
    // проверка на простое число
    int lower_prime = number;
    int upper_prime = number;

    while (!is_prime(lower_prime)) {
        lower_prime--;
    }

    while (!is_prime(upper_prime)) {
        upper_prime++;
    }

    if (number - lower_prime <= upper_prime - number) {
        std::cout << lower_prime;
    } else {
        std::cout << upper_prime;
    }

    return 0;
}